package org.wsff.tools.api.gateway.impl;

import java.io.Serializable;

import org.springframework.stereotype.Service;
import org.wsff.tools.api.gateway.core.GatewayContext;
import org.wsff.tools.api.gateway.core.monitor.AbstractMonitorGateway;
import org.wsff.tools.api.gateway.core.monitor.GatewayMonitor;

/**
 * 默认的网关实现
 *
 * @author ryan
 * @version Id: GenericGateway.java, v 0.1 2022-01-19 17:26 ryan Exp $$
 */
@Service
public class GenericGateway<Request extends Serializable, Response extends Serializable> extends AbstractMonitorGateway<Request, Response> {

    /**
     * 构建网关上下文
     *
     * @param request request
     * @param name proxy name
     * @return context
     */
    @Override
    protected GatewayContext<Request, Response> buildGatewayContext(Request request, String name) {
        return new GenericGatewayContext<>(name, request);
    }

    /**
     * 获取网关监控服务实现
     *
     * @return 网关监控服务实现
     */
    @Override
    protected GatewayMonitor getGatewayMonitor() {
        GatewayMonitor gatewayMonitor = super.getGatewayMonitor();
        if (gatewayMonitor == null) {
            setGatewayMonitor(DefaultGatewayMonitor.instance());
            gatewayMonitor = super.getGatewayMonitor();
        }
        return gatewayMonitor;
    }
}
